﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Product_Search : System.Web.UI.Page
{
    protected void Page_PreInit(object sender, EventArgs e)
    {
        Page.Theme = BLL.Common.GetWSThemes();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        Page.Title = BasePage.WebTitle;
        if (!IsPostBack)
        {
            if (Request.QueryString["Key"] == null)
            {
                Init_Category();
            }
            else
            {
                GetKeySearch();
            }
        }
    }
    #region 初始化分类
    private void Init_Category()
    {
        DDL_Category.DataSource = new BLL.SHANGPIN().GetSPCOMMODITY_TYPEList(0);
        DDL_Category.DataTextField = "CT_Name";
        DDL_Category.DataValueField = "CT_Code";
        DDL_Category.DataBind();        
    }
    #endregion

    #region keyword查找
    #region 返回条例条件的商品IDList
    private void GetKeySearch()
    {
        string key = Request.QueryString["Key"].ToString();
        DataSet ds = new BLL.SHANGPIN().GetKeyPIDList(key);
        if (ds != null)
        {
            if (ds.Tables[0].Rows.Count == 1)
            {
                Response.Redirect("P_" + ds.Tables[0].Rows[0]["SPDM"].ToString() + ".html");
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "", "KeyInitPage();", true);
            }
        }
        else
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "", "noresult();", true);
        }
    }

    #endregion
    #endregion
}
